package com.hc.action;

import com.hc.file.util.SystemConfigUtil;
import com.hc.map.MapArea;
import com.hc.map.MapAreaDot;
import com.hc.util.CommonData;

public class MapAreaAction {
	public static boolean setArea(String areaInfo){
		try {
			String[] str = areaInfo.split(":");
			int x1 = Integer.parseInt(str[0].split(",")[0]);
			int y1 = Integer.parseInt(str[0].split(",")[1]);
			
			int x2 = Integer.parseInt(str[1].split(",")[0]);
			int y2 = Integer.parseInt(str[1].split(",")[1]);
			
			int x3 = Integer.parseInt(str[2].split(",")[0]);
			int y3 = Integer.parseInt(str[2].split(",")[1]);
			
			int x4 = Integer.parseInt(str[3].split(",")[0]);
			int y4 = Integer.parseInt(str[3].split(",")[1]);
			
			int areaId = Integer.parseInt(str[4]);
			MapArea area = new MapArea(areaId, new MapAreaDot(x1, y1), new MapAreaDot(x2, y2), new MapAreaDot(x3, y3), new MapAreaDot(x4, y4));
			CommonData.areaMap.put(areaId, area);
			SystemConfigUtil.writeConfig();
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	
	public static MapArea getMapInfo(int areaId){
		return CommonData.areaMap.containsKey(areaId) ? CommonData.areaMap.get(areaId) : null;
	}
}
